n = 4   # 人数
r = 5   # 水龙头数
p = [2,6,4,5]
p.sort()
s = []
for i in range(r):
    s.append(0)

for i in range(0, n):
    a = i % r
    s[a] += s[a] + p[i]

sum = 0
for i in range(r):
    sum += s[i]

print(sum)

